package com.krmes.mes.app;

import android.content.Context;

import java.io.IOException;
import java.net.ConnectException;
import java.net.SocketException;
import java.net.UnknownHostException;



public class AppException
        extends Exception
        implements Thread.UncaughtExceptionHandler
{
    public static final byte TYPE_FILENOTFOUND = 9;
    public static final byte TYPE_HTTP_CODE = 3;
    public static final byte TYPE_HTTP_ERROR = 4;
    public static final byte TYPE_IO = 6;
    public static final byte TYPE_JSON = 8;
    public static final byte TYPE_NETWORK = 1;
    public static final byte TYPE_RUN = 7;
    public static final byte TYPE_SOCKET = 2;
    public static final byte TYPE_XML = 5;
    private int code;
    private byte type;

    private AppException(byte paramByte, int paramInt, Exception paramException)
    {
        super(paramException);
        this.type = paramByte;
        this.code = paramInt;
    }

    private AppException(Context paramContext) {}

    public static AppException file(Exception paramException)
    {
        return new AppException((byte)9, 0, paramException);
    }

    public static AppException getAppExceptionHandler(Context paramContext)
    {
        return new AppException(paramContext.getApplicationContext());
    }

    public static AppException http(int paramInt)
    {
        return new AppException((byte)3, paramInt, null);
    }

    public static AppException http(Exception paramException)
    {
        return new AppException((byte)4, 0, paramException);
    }

    public static AppException io(Exception paramException)
    {
        return io(paramException, 0);
    }

    public static AppException io(Exception paramException, int paramInt)
    {
        if (((paramException instanceof UnknownHostException)) || ((paramException instanceof ConnectException))) {
            return new AppException((byte)1, paramInt, paramException);
        }
        if ((paramException instanceof IOException)) {
            return new AppException((byte)6, paramInt, paramException);
        }
        return run(paramException);
    }

    public static AppException json(Exception paramException)
    {
        return new AppException((byte)8, 0, paramException);
    }

    public static AppException network(Exception paramException)
    {
        if (((paramException instanceof UnknownHostException)) || ((paramException instanceof ConnectException))) {
            return new AppException((byte)1, 0, paramException);
        }
//        if ((paramException instanceof HttpException)) {
////            return http(paramException);
////        }
        if ((paramException instanceof SocketException)) {
            return socket(paramException);
        }
        return http(paramException);
    }

    public static AppException run(Exception paramException)
    {
        return new AppException((byte)7, 0, paramException);
    }

    public static AppException socket(Exception paramException)
    {
        return new AppException((byte)2, 0, paramException);
    }

    public static AppException xml(Exception paramException)
    {
        return new AppException((byte)5, 0, paramException);
    }

    public int getCode()
    {
        return this.code;
    }

    public int getType()
    {
        return this.type;
    }

    public void uncaughtException(Thread paramThread, Throwable paramThrowable)
    {
        System.exit(0);
    }
}
